package com.huadao.cart_ccs.data.bo;

import com.huadao.cart_ccs.R;
import com.huadao.cart_ccs.common.ByteUtils;
import com.huadao.cart_ccs.common.deviceController.ElectronicScaleController;
import com.huadao.cart_ccs.main.CartApplication;

/**
 * 电子秤
 */
public class ElectronicScaleBO extends BaseBO {

    public static final byte ModularType_ElectronicScale =0x6;
    public static final byte electronicScale_NO1 = 0x01;//电子秤
    public static final byte peel= (byte) 0xBB;//去皮
    public static final byte read= (byte) 0xFF;//读

    private double weight;//重量
    //去皮返回的ad值，若为0000，则由下位机自动去皮
    private byte[] ad;

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    @Override
    protected String getOrderStr() {
        String orderStr = null;
        if (order == peel) {
            orderStr = CartApplication.getInstance().getString(R.string.peel);
        } else if (order == read) {
            orderStr = CartApplication.getInstance().getString(R.string.read);
        }
        return orderStr;
    }

    @Override
    protected String getOrderContentStr() {
        StringBuilder stringBuilder = new StringBuilder();
        if(order==read){
            stringBuilder.append("重量:");
            stringBuilder.append(weight);
            stringBuilder.append("克");
            stringBuilder.append(" 校准重量:");
            stringBuilder.append(getAdjustWeight());
            stringBuilder.append("克");
        }else if(order==peel){
            stringBuilder.append("AD值:");
            stringBuilder.append(ByteUtils.getHexByte(ad,0,ad.length));
        }
        return stringBuilder.toString();
    }

    @Override
    protected String getModularTypeStr() {
        return CartApplication.getInstance().getString(R.string.electronicScale);
    }

    public byte[] getAd() {
        return ad;
    }

    public void setAd(byte[] ad) {
        this.ad = ad;
    }

    //校准后的值
    public double getAdjustWeight() {
        return ElectronicScaleController.calculatedWeight(weight);
    }
}
